<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :inline="true">
      <el-form-item label="报工账号" prop="userName">
        <el-input v-model="form.userName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="工序名称" prop="processName">
        <el-input v-model="form.processName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="workDate" label="日期" align="center"/>
      <el-table-column prop="userName" label="报工账号" align="center"/>
      <el-table-column prop="processName" label="工序名称" align="center"/>
      <el-table-column prop="salary" label="计件工资(元)" align="center"/>
      <el-table-column prop="produceNum" label="生产数量" align="center"/>
      <el-table-column prop="invalidNum" label="不合格数量" align="center"/>
      <el-table-column prop="deptName" label="合格率" align="center">
        <template slot-scope="scope">
         <div>
           {{getRate(scope.row.produceNum,scope.row.invalidNum)}}%
         </div>
        </template>
      </el-table-column>
      <el-table-column prop="deptName" label="所属部门" align="center"/>
    </el-table>
    <pagination
      :total="total"
      :page.sync="form.pageNum"
      :limit.sync="form.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listWorkTotal} from "../../../api/produceMng";

export default {
  data() {
    return {
      loading: false,
      list: [],
      form: {
        userName: "",
        processName: "",
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.handleQuery()
    },
    getRate(total,num){
      return (total - num)/total *100
    },
    handleQuery() {
      this.form.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('form')
      this.handleQuery()
    },
    getList() {
      this.loading = true
      listWorkTotal(this.form).then(res => {
        this.list = res.rows
        this.total = res.total
      }).finally(e => {
        this.loading = false
      })
    }
  }
}
</script>
